#include "StdAfx.h"
#include "Log.h"
#include <time.h>

Log::Log(void)
{
}

Log::~Log(void)
{
}

static FILETIME ft;
static SYSTEMTIME st = {0};
static char time_buffer[24] = {0};
static DWORD offset = 0;
static DWORD tick = 0;
static DWORD ms = 0;

void InitLog(){
	GetLocalTime(&st);
	int s = st.wSecond;
	while (true)
	{
		GetLocalTime(&st);		

		// wait for a rollover
		if (st.wSecond != s)
		{
			offset = GetTickCount() % 1000;
			break;
		}
	}
}

const char * Now(){		
	GetLocalTime(&st); 
	tick = GetTickCount() % 1000;

	// calculate our ms shift from our base m_offset
	ms = (tick >= offset) ? (tick - offset) : (1000 - (offset - tick));

	/*
	GetSystemTimeAsFileTime(&ft);		
	FileTimeToSystemTime(&ft, &st);
	*/
	sprintf(time_buffer,"%4d-%02d-%02d %02d:%02d:%02d:%03d", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond,ms/*st.wMilliseconds*/); 
	return time_buffer;
}